<#include "macro.include"/>
<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
package ${basepackage}.${subpackage}.entity;

public class ${className} extends BaseEntity {
	<@generateFields/>
	<@generateCompositeIdConstructorIfis/>
	<@generatePkProperties/>
	<@generateNotPkProperties/>
	<@generateJavaOneToMany/>
	<@generateJavaManyToOne/>
}

<#macro generateFields>
<#if table.compositeId>
	private ${className}Id id;
	<#list table.columns as column>
		<#if !column.pk>
	private ${column.javaType} ${column.columnNameLower};
		</#if>
	</#list>
<#else>
	<#list table.columns as column>
	private ${column.javaType} ${column.columnNameLower};
	</#list>
</#if>
</#macro>

<#macro generateCompositeIdConstructorIfis>

	<#if table.compositeId>
	public ${className}(){
	}
	public ${className}(${className}Id id) {
		this.id = id;
	}
	<#else>
	<@generateConstructor className/>
	</#if>
</#macro>

<#macro generatePkProperties>
	<#if table.compositeId>
		@EmbeddedId
		public ${className}Id getId() {
			return this.id;
		}
		
		public void setId(${className}Id id) {
			this.id = id;
		}
	<#else>
		<#list table.columns as column>
			<#if column.pk>
	public void set${column.columnName}(${column.javaType} ${column.columnNameLower}) {
		this.${column.columnNameLower} = ${column.columnNameLower};
	}
	
	public ${column.javaType} get${column.columnName}() {
		return this.${column.columnNameLower};
	}
			</#if>
		</#list>
	</#if>
</#macro>

<#macro generateNotPkProperties>
	<#list table.columns as column>
		<#if !column.pk>
			<#if column.isDateTimeColumn>
	public String get${column.columnName}String() {
		return convertDate2String(get${column.columnName}(), FORMAT_${column.sqlName?upper_case});
	}
	public void set${column.columnName}String(String value) {
		set${column.columnName}(convertString2Date(value, FORMAT_${column.sqlName?upper_case}));
	}
			</#if>
	public ${column.javaType} get${column.columnName}() {
		return this.${column.columnNameLower};
	}
	
	public void set${column.columnName}(${column.javaType} ${column.columnNameLower}) {
		this.${column.columnNameLower} = ${column.columnNameLower};
	}
	
		</#if>
	</#list>
</#macro>

<#macro generateJavaOneToMany>
	<#list table.exportedKeys.associatedTables?values as foreignKey>
		<#assign fkSqlTable = foreignKey.sqlTable>
		<#assign fkTable    = fkSqlTable.className>
		<#assign fkPojoClass = fkSqlTable.className>
		<#assign fkPojoClassVar = fkPojoClass?uncap_first>
		
		private Set ${fkPojoClassVar}s = new HashSet(0);
		public void set${fkPojoClass}s(Set<${fkPojoClass}> ${fkPojoClassVar}){
			this.${fkPojoClassVar}s = ${fkPojoClassVar};
		}
		
		public Set<${fkPojoClass}> get${fkPojoClass}s() {
			return ${fkPojoClassVar}s;
		}
	</#list>
</#macro>

<#macro generateJavaManyToOne>
	<#list table.importedKeys.associatedTables?values as foreignKey>
		<#assign fkSqlTable = foreignKey.sqlTable>
		<#assign fkTable    = fkSqlTable.className>
		<#assign fkPojoClass = fkSqlTable.className>
		<#assign fkPojoClassVar = fkPojoClass?uncap_first>
		
		private ${fkPojoClass} ${fkPojoClassVar};
		
		public void set${fkPojoClass}(${fkPojoClass} ${fkPojoClassVar}){
			this.${fkPojoClassVar} = ${fkPojoClassVar};
		}
		
		<#list foreignKey.parentColumns?values as fkColumn>
    </#list>
	public ${fkPojoClass} get${fkPojoClass}() {
		return ${fkPojoClassVar};
	}
	</#list>
</#macro>

